import  java.sql.*;
public class Main {

    public static void main(String[] args) {
//      1.注册驱动
        Connection conn = null;
        Statement statement = null;
        ResultSet res = null;
        try {
            Driver driver = new com.mysql.jdbc.Driver();
            DriverManager.registerDriver(driver);
//            2.获取数据库连接
            String url = "jdbc:mysql://localhost:3306/tabletest?characterEncoding=utf8&useSSL=false";
//            String url = "url=jdbc:mysql://localhost:3306/bjnode/framework?characterEncoding=utf8&useSSL=false";
            String user = "root";
            String password = "root";
            conn = DriverManager.getConnection(url, user, password);
//            3.获取数据操作的对象
            statement = conn.createStatement();
//            4.执行SQL语句，DML语句
            String sql = "select * from users";
            res = statement.executeQuery(sql);
//            5.处理查询结果集
            while (res.next()) {
                String enmae = res.getString("name");
                String sal = res.getString("password");
                System.out.println(enmae+"  "+sal+"  ");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}